package com.fjjn;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.fjjn.handler.YztMetaObjectHandler;
import com.fjjn.plugins.YztPaginationInnerInterceptor;
import com.fjjn.resolver.SqlFilterArgumentResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration(proxyBeanMethods = false)
public class MybatisAutoConfiguration implements WebMvcConfigurer {

	/**
	 * SQL 过滤器避免SQL 注入
     */
	@Override
	public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
		argumentResolvers.add(new SqlFilterArgumentResolver());
	}

	/**
	 * 分页插件, 对于单一数据库类型来说,都建议配置该值,避免每次分页都去抓取数据库类型
	 */
	@Bean
	public MybatisPlusInterceptor mybatisPlusInterceptor() {
		MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
		interceptor.addInnerInterceptor(new YztPaginationInnerInterceptor());
		return interceptor;
	}

	/**
	 * 审计字段自动填充
	 */
	@Bean
	public YztMetaObjectHandler mybatisPlusMetaObjectHandler() {
		return new YztMetaObjectHandler();
	}

}